-- AppleTVdataMaker.applescript
-- AppleTVdataMaker

--  Created by Thomas De Groote on 1/11/07.
--  Copyright 2007-2008 Thomas De Groote. All rights reserved.

property MovieBaseDir : null
property myPath : (path to me)
property phpversion : 4
property ToolsBaseDir : null
property previousFile : ""


on will finish launching theObject
	set phpversion to do shell script "php -v"
	if ((characters 5 thru 5 of phpversion as text) = "5") then
		-- enable subtitles...
		--		set enabled of button "checkSUBS" of window "Main Window" to true
	else
		-- keep disabled
		set enabled of button "checkSUBS" of tab view item 1 of tab view 1 of window "Main Window" to false
		set title of button "checkSUBS" of tab view item 1 of tab view 1 of window "Main Window" to "Download subtitles (Leopard/php5 only)"
	end if
	try
		tell user defaults
			make new default entry at end of default entries of user defaults with properties {name:"subtitleLanguage", contents:{}}
		end tell
	end try
	set myPath to (path to me as string)
	set grabberphp to POSIX path of file (myPath)
	set blabla to do shell script "php " & grabberphp & "Contents/Resources/makecachedir.php"
end will finish launching

on clicked theObject
	if name of theObject is "chooseWorkDir" then
		set MovieBaseDir to choose folder with prompt "Please select a folder of items to process:"
		set contents of text field "dropWorkDir" of tab view item 1 of tab view 1 of window "Main Window" to POSIX path of MovieBaseDir as string
		
	else if name of theObject is "StartMovies" then
		set MovieBaseDir to POSIX file (contents of text field "dropWorkDir" of tab view item 1 of tab view 1 of window "Main Window")
		set theMovieDirs to list folder MovieBaseDir without invisible
		
		set tempVar to current row of matrix 1 of tab view item 5 of tab view 1 of window "Main Window" -- movies per folder or thrown together in one folder
		start progress indicator "barProgressDirs" of tab view item 1 of tab view 1 of window "Main Window"
		set indeterminate of progress indicator "barProgressDirs" of tab view item 1 of tab view 1 of window "Main Window" to false
		if (tempVar = 1) then
			set maximum value of progress indicator "barProgressDirs" of tab view item 1 of tab view 1 of window "Main Window" to length of theMovieDirs
			set content of progress indicator "barProgressDirs" of tab view item 1 of tab view 1 of window "Main Window" to 0
			
			repeat with a from 1 to length of theMovieDirs
				set this_item to alias ((MovieBaseDir as text) & (item a of theMovieDirs))
				set the item_info to info for this_item
				if folder of the item_info is true then
					set content of text field "curMovieDir" of tab view item 1 of tab view 1 of window "Main Window" to item a of theMovieDirs as string
					set temp to content of progress indicator "barProgressDirs" of tab view item 1 of tab view 1 of window "Main Window"
					set content of progress indicator "barProgressDirs" of tab view item 1 of tab view 1 of window "Main Window" to (temp + 1)
					try
						processMovie(this_item)
					end try
				else
					set maximum value of progress indicator "barProgressDirs" of tab view item 1 of tab view 1 of window "Main Window" to ((maximum value of progress indicator "barProgressDirs" of tab view item 1 of tab view 1 of window "Main Window") - 1)
				end if
			end repeat
			
			display dialog ("All done!") buttons {"OK"} default button "OK"
		else
			-- All movies together in one big folder...
			set myPath to (path to me as string)
			set grabberphp to POSIX path of file (myPath) --  & 'Contents:Resources:grabber.php')
			set movieFileList to do shell script "php " & grabberphp & "Contents/Resources/movies_separate_list.php '" & (contents of text field "dropWorkDir" of tab view item 1 of tab view 1 of window "Main Window") & "'"
			set maximum value of progress indicator "barProgressDirs" of tab view item 1 of tab view 1 of window "Main Window" to (count paragraphs of movieFileList)
			set content of progress indicator "barProgressDirs" of tab view item 1 of tab view 1 of window "Main Window" to 0
			
			if (integer value of button "checkSUBS" of tab view item 1 of tab view 1 of window "Main Window") = 1 then
				display dialog ("In this version subtitle downloading does not yet work when working with non-sorted movies.") buttons {"OK"} default button "OK"
			end if
			
			repeat with i from 1 to (count paragraphs of movieFileList)
				if (i > 1) then
					set previousFile to paragraph (i - 1) of movieFileList
				end if
				set content of text field "curMovieDir" of tab view item 1 of tab view 1 of window "Main Window" to paragraph i of movieFileList
				set temp to content of progress indicator "barProgressDirs" of tab view item 1 of tab view 1 of window "Main Window"
				set content of progress indicator "barProgressDirs" of tab view item 1 of tab view 1 of window "Main Window" to (temp + 1)
				try
					processMovieByFile(quoted form of paragraph i of movieFileList)
				end try
			end repeat
			display dialog ("And we are done again!") buttons {"OK"} default button "OK"
		end if
	else if name of theObject is "chooseSerieBase" then
		set SeriesBaseDir to choose folder with prompt "Please select a folder of series to process:"
		set contents of text field "dropWorkDir" of tab view item 2 of tab view 1 of window "Main Window" to POSIX path of SeriesBaseDir as string
		
	else if name of theObject is "StartSeries" then
		set SeriesBaseDir to POSIX file (contents of text field "dropWorkDir" of tab view item 2 of tab view 1 of window "Main Window")
		set theSeriesDirs to list folder SeriesBaseDir without invisible
		
		
		set this_path to POSIX path of SeriesBaseDir
		set myPath to (path to me as string)
		set grabberphp to POSIX path of file (myPath) --  & 'Contents:Resources:grabber.php')
		
		set seriesIndex to do shell script "php " & grabberphp & "Contents/Resources/series_prepare.php '" & this_path & "'"
		
		set srtLanguage to (title of current menu item of popup button "langpopup" of tab view item 5 of tab view 1 of window "Main Window")
		
		
		start progress indicator "barProgressDirs" of tab view item 2 of tab view 1 of window "Main Window"
		set indeterminate of progress indicator "barProgressDirs" of tab view item 2 of tab view 1 of window "Main Window" to false
		set maximum value of progress indicator "barProgressDirs" of tab view item 2 of tab view 1 of window "Main Window" to (count paragraphs of seriesIndex)
		set content of progress indicator "barProgressDirs" of tab view item 2 of tab view 1 of window "Main Window" to 0
		
		set text item delimiters to tab
		repeat with i from 1 to (count paragraphs of seriesIndex)
			set content of progress indicator "barProgressDirs" of tab view item 2 of tab view 1 of window "Main Window" to i
			set theSerieFile to paragraph i of seriesIndex
			set seriesIndexCurAr to text items of theSerieFile
			set content of text field "curSerieDir" of tab view item 2 of tab view 1 of window "Main Window" to item 2 of seriesIndexCurAr
			set content of control "lightXML" of tab view item 2 of tab view 1 of window "Main Window" to item 5 of seriesIndexCurAr
			set content of control "lightCover" of tab view item 2 of tab view 1 of window "Main Window" to item 8 of seriesIndexCurAr
			set content of control "lightSRT" of tab view item 2 of tab view 1 of window "Main Window" to item 6 of seriesIndexCurAr
			set content of control "lightSHOT" of tab view item 2 of tab view 1 of window "Main Window" to item 7 of seriesIndexCurAr
			--		display dialog (item 2 of seriesIndexCurAr)
			-- subtitle download?
			if (integer value of button "checkSUBS" of tab view item 2 of tab view 1 of window "Main Window") = 1 then
				if (get content of control "lightSRT" of tab view item 2 of tab view 1 of window "Main Window" = 3) then
					set tempVar to do shell script "php " & grabberphp & "Contents/Resources/series_process.php '" & item 1 of seriesIndexCurAr & "' '" & grabberphp & "' 1 '" & srtLanguage & "'"
				else
					set tempVar to do shell script "php " & grabberphp & "Contents/Resources/series_process.php '" & item 1 of seriesIndexCurAr & "' '" & grabberphp & "'"
				end if
			else
				set tempVar to do shell script "php " & grabberphp & "Contents/Resources/series_process.php '" & item 1 of seriesIndexCurAr & "' '" & grabberphp & "'"
			end if
			if tempVar is not "" then
				set tempVars to text items of tempVar
				try
					set image of image view "coverPreview" of window "Main Window" to (load image item 1 of tempVars)
				end try
				set content of control "lightCover" of tab view item 2 of tab view 1 of window "Main Window" to item 2 of tempVars
			end if
			
		end repeat
		
		display dialog ("All done!") buttons {"OK"} default button "OK"
	else if name of theObject is "checkCovers" then
		set myVariable to title of popup button "coverSystem" of tab view item 1 of tab view 1 of window "Main Window" -- popup button "control" of theWindow
		if (((integer value of button "checkCovers" of tab view item 1 of tab view 1 of window "Main Window") = 1) and (characters 1 thru 1 of myVariable as text is "M")) then
			display dialog ("This will ask a URL for every cover!") buttons {"OK"} default button "OK"
		end if
	else if name of theObject is "chooseToolsWorkDir" then
		set ToolsBaseDir to choose folder with prompt "Please select a folder of items to process:"
		set ToolsBaseDirDirs to list folder ToolsBaseDir without invisible
		set contents of text field "dropToolsWorkDir" of tab view item 3 of tab view 1 of window "Main Window" to POSIX path of ToolsBaseDir as string
	else if name of theObject is "makegnrbtn" then
		-- We have to make the genres etc directories...
		set myPath to (path to me as string)
		set tempVar to (contents of text field "dropToolsWorkDir" of tab view item 3 of tab view 1 of window "Main Window")
		set grabberphp to POSIX path of file (myPath) --  & 'Contents:Resources:grabber.php')
		set blabla to do shell script "php " & grabberphp & "Contents/Resources/makedirs.php '" & tempVar & "' '" & grabberphp & "'"
		display dialog ("Done creating directories") buttons {"OK"} default button "OK"
	else if name of theObject is "makequicksiteiphone" then
		set myPath to (path to me as string)
		set tempVar to (contents of text field "dropToolsWorkDir" of tab view item 3 of tab view 1 of window "Main Window")
		set destinationDir to choose folder with prompt "Please select a folder in which to create the site:"
		set grabberphp to POSIX path of file (myPath)
		set websitephp to POSIX path of destinationDir
		
		set blabla to do shell script "php " & grabberphp & "Contents/Resources/makewebsite_iphone.php '" & tempVar & "' '" & websitephp & "'"
		display dialog ("Done creating iphone website") buttons {"OK"} default button "OK"
	else if name of theObject is "makequicksite" then
		set myPath to (path to me as string)
		set tempVar to (contents of text field "dropToolsWorkDir" of tab view item 3 of tab view 1 of window "Main Window")
		set destinationDir to choose folder with prompt "Please select a folder in which to create the site:"
		set grabberphp to POSIX path of file (myPath)
		set websitephp to POSIX path of destinationDir
		
		set blabla to do shell script "php " & grabberphp & "Contents/Resources/makewebsite_base.php '" & websitephp & "'"
		set blabla to do shell script "php " & grabberphp & "Contents/Resources/makewebsite.php '" & tempVar & "' '" & websitephp & "'"
		display dialog ("Done creating website") buttons {"OK"} default button "OK"
	else if name of theObject is "updatequicksite" then
		set myPath to (path to me as string)
		set tempVar to (contents of text field "dropToolsWorkDir" of tab view item 3 of tab view 1 of window "Main Window")
		set destinationDir to choose folder with prompt "Please select a folder in which to create the site:"
		set grabberphp to POSIX path of file (myPath)
		set websitephp to POSIX path of destinationDir
		
		set blabla to do shell script "php " & grabberphp & "Contents/Resources/makewebsite.php '" & tempVar & "' '" & websitephp & "'"
		display dialog ("Done updating website") buttons {"OK"} default button "OK"
	else if name of theObject is "testing" then
		--		set tempVar to current row of matrix 1 of tab view item 4 of tab view 1 of window "Main Window"
		--		display dialog "Selected item " & tempVar
		set p to POSIX file (contents of text field "dropToolsWorkDir" of tab view item 3 of tab view 1 of window "Main Window")
		set thePdirs to list folder p without invisible
		display dialog ("Number of items " & length of thePdirs)
		repeat with a from 1 to length of thePdirs
			display dialog (item a of thePdirs as string)
		end repeat
	else if name of theObject is "SSH_ResetFinder" then
		set sshIP to (contents of text field "sshprefs_IP" of tab view item 4 of tab view 1 of window "Main Window")
		set sshLogin to (contents of text field "sshprefs_login" of tab view item 4 of tab view 1 of window "Main Window")
		set sshPassw to (contents of text field "sshprefs_passw" of tab view item 4 of tab view 1 of window "Main Window")
		
		set temp to do shell script "ssh -i " & sshPassw & " " & sshLogin & "@" & sshIP & " 'for X in `ps acx|grep Finder`; do echo $X; done'"
		set temp to paragraph (1) of temp
		set temp to do shell script "ssh -i " & sshPassw & " " & sshLogin & "@" & sshIP & " 'kill " & temp & "'"
		--		display dialog "SSH Command to send: " buttons {"OK"} default button "OK" default answer "kill " & temp
	else if name of theObject is "SSH_BuildRecent" then
		set sshIP to (contents of text field "sshprefs_IP" of tab view item 4 of tab view 1 of window "Main Window")
		set sshLogin to (contents of text field "sshprefs_login" of tab view item 4 of tab view 1 of window "Main Window")
		set sshPassw to (contents of text field "sshprefs_passw" of tab view item 4 of tab view 1 of window "Main Window")
		set sshMovDir to display dialog "Please enter path to movies directory: " buttons {"Cancel", "OK"} default button "OK" default answer "/Volumes/Movies/Alphabetical/"
		if (sshMovDir is not "") then
			set temp to do shell script "ssh -i " & sshPassw & " " & sshLogin & "@" & sshIP & " 'mkdir /Users/frontrow/Movies/Recent/; rm /Users/frontrow/Movies/Recent/*; find /Volumes/Movies/Alphabetical/ -type d -mtime -20 -exec ln -s {} /Users/frontrow/Movies/Recent/ \\;'"
			display dialog "SSH Command to send: " buttons {"OK"} default button "OK" default answer "'mkdir /Users/frontrow/Movies/Recent/; rm /Users/frontrow/Movies/Recent/*; find /Volumes/Movies/Alphabetical/ -type d -mtime -20 -exec ln -s {} /Users/frontrow/Movies/Recent/ \\;'"
		end if
	else if name of theObject is "SSH_CopyShotsNito" then
		set sshIP to (contents of text field "sshprefs_IP" of tab view item 4 of tab view 1 of window "Main Window")
		set sshLogin to (contents of text field "sshprefs_login" of tab view item 4 of tab view 1 of window "Main Window")
		set sshPassw to (contents of text field "sshprefs_passw" of tab view item 4 of tab view 1 of window "Main Window")
		set sshMovDir to display dialog "Please enter path to movies directory: " buttons {"Cancel", "OK"} default button "OK" default answer "/Volumes/Movies/Alphabetical/"
		if (sshMovDir is not "") then
			--			set temp to do shell script "ssh -i " & sshPassw & " " & sshLogin & "@" & sshIP & " 'cd /Users/frontrow/Library/Application\\ Support/nito/images; find " & sshMovDir & " -name \"*.jpg\" ! -name \"cover.jpg\" -exec ln -s {} /Users/frontrow/Library/Application\\ Support/nito/images/ \\;'"
			display dialog "SSH Command to send: " buttons {"OK"} default button "OK" default answer "ssh -i " & sshPassw & " " & sshLogin & "@" & sshIP & " 'cd /Users/frontrow/Library/Application\\ Support/nito/images; find /Volumes/Movies/Alphabetical/ -name \"*.jpg\" ! -name \"cover.jpg\" -exec ln -s {} /Users/frontrow/Library/Application\\ Support/nito/images/ \\;'"
		end if
	end if
end clicked


on conclude drop theObject drag info dragInfo
	(*Add your script here.*)
end conclude drop

on panel ended theObject with result withResult
	(*Add your script here.*)
end panel ended

on choose menu item theObject
	if (name of theObject is "coverSystem") then
		set myVariable to title of popup button "coverSystem" of tab view item 1 of tab view 1 of window "Main Window" -- popup button "control" of theWindow
		if (((integer value of button "checkCovers" of tab view item 1 of tab view 1 of window "Main Window") = 1) and (characters 1 thru 1 of myVariable as text is "M")) then
			display dialog ("This will ask a URL for every cover!") buttons {"OK"} default button "OK"
		end if
	else if (name of theObject is "aboutMenu") then
		show window "aboutWin"
		--		display dialog (name of theObject as string)
	end if
end choose menu item

on should quit after last window closed theObject
	(*Add your script here.*)
	return true
end should quit after last window closed

on should close theObject
	(*Add your script here.*)
	tell theObject to hide
end should close


on processMovie(moviePath)
	set content of text field "imdbnr" of tab view item 1 of tab view 1 of window "Main Window" to moviePath as string
	set myPath to (path to me as string)
	set grabberphp to POSIX path of file (myPath) --  & 'Contents:Resources:grabber.php')
	set posixmovie to POSIX path of moviePath --  & 'Contents:Resources:grabber.php')
	
	-- get imdb number
	set myimdbnr to do shell script "php " & grabberphp & "Contents/Resources/imdbnr.php " & quoted form of posixmovie
	set contents of text field "imdbnr" of tab view item 1 of tab view 1 of window "Main Window" to myimdbnr as string
	
	-- read contents...
	-- count avi / srt / jpg / sample / trailer ...
	set mystatus to do shell script "php " & grabberphp & "Contents/Resources/status.php " & quoted form of posixmovie
	set AppleScript's text item delimiters to ""
	set content of control "lightXML" of tab view item 1 of tab view 1 of window "Main Window" to item 1 of mystatus
	set content of control "lightCover" of tab view item 1 of tab view 1 of window "Main Window" to item 2 of mystatus
	set content of control "lightSRT" of tab view item 1 of tab view 1 of window "Main Window" to item 3 of mystatus
	set content of control "lightTRL" of tab view item 1 of tab view 1 of window "Main Window" to item 4 of mystatus
	
	-- create XML files
	if (item 1 of mystatus > 1) or ((integer value of button "checkXML" of tab view item 1 of tab view 1 of window "Main Window") = 1) then
		if (myimdbnr > 0) then
			if (integer value of button "checkCHRIS" of tab view item 1 of tab view 1 of window "Main Window") = 1 then
				set content of control "lightXML" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/makexml.php " & quoted form of posixmovie & " " & myimdbnr & " chris"
			else
				set content of control "lightXML" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/makexml.php " & quoted form of posixmovie & " " & myimdbnr
			end if
		else
			set theReply to display dialog ("Could not find the IMDB number for movie \"" & content of text field "curMovieDir" of tab view item 1 of tab view 1 of window "Main Window" & "\". Can you help me?") default answer "" buttons {"Cancel", "That's it"} default button "That's it" giving up after 120
			set myimdbnr to text returned of theReply
			if (myimdbnr ≠ "") and (myimdbnr > 0) then
				if (integer value of button "checkCHRIS" of tab view item 1 of tab view 1 of window "Main Window") = 1 then
					set content of control "lightXML" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/makexml.php " & quoted form of posixmovie & " " & myimdbnr & " chris"
				else
					set content of control "lightXML" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/makexml.php " & quoted form of posixmovie & " " & myimdbnr
				end if
			end if
		end if
	end if
	
	-- do we want subtitle downloads?
	if (integer value of button "checkSUBS" of tab view item 1 of tab view 1 of window "Main Window") = 1 then
		set srtLanguage to (title of current menu item of popup button "langpopup" of tab view item 5 of tab view 1 of window "Main Window")
		set content of control "lightSRT" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/getsubtitles.php " & quoted form of posixmovie & " " & myimdbnr & " '" & srtLanguage & "'"
		
	end if
	
	-- cover download...
	-- should be last, as this includes a dialog box and pressing cancel here for some reason breaks out of the method...
	if (integer value of button "checkCovers" of tab view item 1 of tab view 1 of window "Main Window") = 1 then
		if (item 2 of mystatus = "2") then
			-- there is a cover, but no copies for the movie files...
			set content of control "lightCover" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/getcover.php " & quoted form of posixmovie & " cover.jpg"
		else if (item 2 of mystatus = "3") then
			-- no cover at all
			set myVariable to title of popup button "coverSystem" of tab view item 1 of tab view 1 of window "Main Window" -- popup button "control" of theWindow
			if (characters 1 thru 1 of myVariable as text is "M") then
				set theReply to display dialog ("Please enter a URL for the cover to be downloaded (.jpg) for \"" & content of text field "curMovieDir" of tab view item 1 of tab view 1 of window "Main Window") & "\"" default answer "http://" buttons {"Cancel", "Download"} default button "Download" giving up after 120
				set coverURL to text returned of theReply
				set state of button "checkCovers" of tab view item 1 of tab view 1 of window "Main Window" to not gave up of theReply -- if no URL is given for 120 seconds, consider user away and stop looking for covers...
				if ((coverURL ≠ "http://") and (coverURL ≠ "")) then
					set content of control "lightCover" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/getcover.php " & quoted form of posixmovie & " " & coverURL
				end if
			else
				set content of control "lightCover" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/getcover_auto.php " & quoted form of posixmovie
			end if
		end if
	end if
	set image of image view "coverPreview" of window "Main Window" to (load image posixmovie & "cover.jpg")
	
	
end processMovie


on processSeries(seriePath)
	
	set myPath to (path to me as string)
	set grabberphp to quoted form of the POSIX path of file (myPath)
	set posixserie to quoted form of the POSIX path of seriePath
	set myimdbnr to do shell script "php " & grabberphp & "Contents/Resources/series.php '" & posixserie & "' '" & grabberphp & "'"
	--	set contents of text view 1 of scroll view "logtextscroller" of window "logwin" to (contents of text view 1 of scroll view "logtextscroller" of window "logwin") & "php " & grabberphp & "Contents/Resources/series.php '" & posixserie & "' '" & grabberphp & "'"
	
	set contents of text view 1 of scroll view "logtextscroller" of window "logwin" to (contents of text view 1 of scroll view "logtextscroller" of window "logwin") & myimdbnr
	
end processSeries



on processMovieByFile(moviePath)
	set content of text field "imdbnr" of tab view item 1 of tab view 1 of window "Main Window" to moviePath as string
	
	set myPath to (path to me as string)
	set grabberphp to quoted form of the POSIX path of file (myPath)
	set posixmovie to moviePath
	
	-- same movie as previous?
	set similarmovie to do shell script "php " & grabberphp & "Contents/Resources/movies_separate_compare.php '" & posixmovie & "' '" & previousFile & "'"
	
	
	-- get imdb number
	set myimdbnr to do shell script "php " & grabberphp & "Contents/Resources/movies_separate_imdbnr.php '" & posixmovie & "'"
	set contents of text field "imdbnr" of tab view item 1 of tab view 1 of window "Main Window" to myimdbnr as string
	
	set filename to do shell script "php " & grabberphp & "Contents/Resources/movies_separate_filename.php '" & posixmovie & "'"
	set contents of text field "curMovieDir" of tab view item 1 of tab view 1 of window "Main Window" to filename as string
	
	-- read contents...
	-- count avi / srt / jpg / sample / trailer ...
	set mystatus to do shell script "php " & grabberphp & "Contents/Resources/movies_separate_status.php '" & posixmovie & "'"
	set AppleScript's text item delimiters to ""
	set content of control "lightXML" of tab view item 1 of tab view 1 of window "Main Window" to item 1 of mystatus
	set content of control "lightCover" of tab view item 1 of tab view 1 of window "Main Window" to item 2 of mystatus
	set content of control "lightSRT" of tab view item 1 of tab view 1 of window "Main Window" to item 3 of mystatus
	--	set content of control "lightTRL" of tab view item 1 of tab view 1 of window "Main Window" to item 4 of mystatus
	
	
	-- create XML files
	if (item 1 of mystatus > 1) or ((integer value of button "checkXML" of tab view item 1 of tab view 1 of window "Main Window") = 1) then
		if (myimdbnr > 0) then
			if (integer value of button "checkCHRIS" of tab view item 1 of tab view 1 of window "Main Window") = 1 then
				set content of control "lightXML" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/movies_separate_makexml.php '" & posixmovie & "' " & myimdbnr & " chris"
			else
				set content of control "lightXML" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/movies_separate_makexml.php '" & posixmovie & "' " & myimdbnr
			end if
		else
			set theReply to display dialog ("Could not find the IMDB number for movie \"" & content of text field "curMovieDir" of tab view item 1 of tab view 1 of window "Main Window" & "\". Can you help me?") default answer "" buttons {"Cancel", "That's it"} default button "That's it" giving up after 120
			set myimdbnr to text returned of theReply
			if (myimdbnr ≠ "") and (myimdbnr > 0) then
				if (integer value of button "checkCHRIS" of tab view item 1 of tab view 1 of window "Main Window") = 1 then
					set content of control "lightXML" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/movies_separate_makexml.php '" & posixmovie & "' " & myimdbnr & " chris"
				else
					set content of control "lightXML" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/movies_separate_makexml.php '" & posixmovie & "' " & myimdbnr
				end if
			end if
		end if
	end if
	
	
	(*

	
	-- do we want subtitle downloads?
	if (integer value of button "checkSUBS" of tab view item 1 of tab view 1 of window "Main Window") = 1 then
		set srtLanguage to (title of current menu item of popup button "langpopup" of tab view item 4 of tab view 1 of window "Main Window")
		set content of control "lightSRT" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/movies_separate_getsubtitles.php '" & posixmovie & "' " & myimdbnr & " '" & srtLanguage & "'"
		
	end if

	*)
	
	-- cover download...
	-- should be last, as this includes a dialog box and pressing cancel here for some reason breaks out of the method...
	if (integer value of button "checkCovers" of tab view item 1 of tab view 1 of window "Main Window") = 1 then
		if (item 2 of mystatus = "3") then
			set myVariable to title of popup button "coverSystem" of tab view item 1 of tab view 1 of window "Main Window" -- popup button "control" of theWindow
			if (characters 1 thru 1 of myVariable as text is "M") then
				set theReply to display dialog ("Please enter a URL for the cover to be downloaded (.jpg) for \"" & content of text field "curMovieDir" of tab view item 1 of tab view 1 of window "Main Window") & "\"" default answer "http://" buttons {"Cancel", "Download"} default button "Download" giving up after 120
				set coverURL to text returned of theReply
				set state of button "checkCovers" of tab view item 1 of tab view 1 of window "Main Window" to not gave up of theReply -- if no URL is given for 120 seconds, consider user away and stop looking for covers...
				if ((coverURL ≠ "http://") and (coverURL ≠ "")) then
					set content of control "lightCover" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/movies_separate_getcover.php '" & posixmovie & "' " & coverURL
				end if
			else
				set content of control "lightCover" of tab view item 1 of tab view 1 of window "Main Window" to do shell script "php " & grabberphp & "Contents/Resources/movies_separate_getcover_auto.php '" & posixmovie & "'"
			end if
		end if
	end if
	set image of image view "coverPreview" of window "Main Window" to (load image posixmovie & "cover.jpg")
	
end processMovieByFile
